#!/bin/bash -e

rm -f $SNAP_COMMON/snap_refresh

# GDK pixbuf setup
export LD_LIBRARY_PATH=/var/lib/snapd/lib/gl:/var/lib/snapd/lib/gl32:/var/lib/snapd/void:${SNAP}/graphics/lib:${SNAP}/lib:${SNAP}/usr/lib:${SNAP}/lib/${ARCH_TRIPLET}:${SNAP}/usr/lib/${ARCH_TRIPLET}
$SNAP/usr/lib/${ARCH_TRIPLET}/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders > "$GDK_PIXBUF_MODULE_FILE"

# GSettings schemas
GS_SCHEMA_DIR=$SNAP_DATA/data/glib-2.0/schemas
mkdir -p "$GS_SCHEMA_DIR"
rm -f "$GS_SCHEMA_DIR"/*

schema_dir="${SNAP}/usr/share/glib-2.0/schemas"
if [ -n "$(ls -A $schema_dir/*.xml 2>/dev/null)" ]; then
  ln -s $schema_dir/*.xml $GS_SCHEMA_DIR
fi
if [ -n "$(ls -A $schema_dir/*.override 2>/dev/null)" ]; then
  ln -s $schema_dir/*.override $GS_SCHEMA_DIR
fi

$SNAP/usr/lib/${ARCH_TRIPLET}/glib-2.0/glib-compile-schemas "$GS_SCHEMA_DIR"
